package com.yoo.module_base.utils

import android.app.Activity
import android.content.Context
import android.os.Vibrator
import android.util.Log
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity
import com.gyf.immersionbar.ImmersionBar
import com.yoo.module_base.BuildConfig
import java.util.concurrent.TimeUnit
import io.reactivex.Observable
import razerdp.basepopup.BasePopupWindow


fun log(message: String, tag: String = "debug_Test") {
    if (BuildConfig.DEBUG) Log.d(tag, message)
}
/**
 * 给view设置'防抖动'点击事件
 * 连续点击在 interval 毫秒内只有1次生效
 */
fun View.setOnClickCallback(interval: Long = 1000L, callback: (View) -> Unit) {
    if (!isClickable) isClickable = true
    if (!isFocusable) isFocusable = true
    Observable.create<View> {
        setOnClickListener(it::onNext)
    }
        .throttleFirst(interval, TimeUnit.MILLISECONDS)
        .doOnNext(callback)
        .subscribe()
}

fun shake(view: View, context: FragmentActivity) {
    val shake: Animation =
        AnimationUtils.loadAnimation(context, com.yoo.module_res.R.anim.emojishake) //加载动画资源文件
    val vibrator = context.getSystemService(AppCompatActivity.VIBRATOR_SERVICE) as Vibrator
    vibrator.vibrate(100)
    view.startAnimation(shake)
}

//设置底部导航栏颜色
fun setSystemBottomNavBarColor(context: Activity){
    ImmersionBar.with(context,true)
        .navigationBarColor("#AA089A")
        .navigationBarEnable(true)
        .init()
}
fun setSystemBottomNavBarNoColor(context: Activity){
    ImmersionBar.with(context,true)
        .navigationBarEnable(false)
        .init()
}